package net.zhengxinyun.performance.service.gradePoint;

import net.zhengxinyun.performance.entity.GradePointEntity;
import net.zhengxinyun.performance.filter.GradePointFilter;
import net.zhengxinyun.performance.mapper.gradePoint.GradePointEntityMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.util.List;

@Service
@Transactional
public class GradePointServiceImp implements GradePointService {


    private GradePointEntityMapper gradePointEntityMapper;

    @Autowired
    public GradePointServiceImp(GradePointEntityMapper gradePointEntityMapper) {
        this.gradePointEntityMapper = gradePointEntityMapper;
    }

    @Override
    public String insert(GradePointEntity gradePointEntity) {
        int i = gradePointEntityMapper.insert(gradePointEntity);
        if (i == 0 ){
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return "添加失败,请联系管理员";
        }
        return "添加成功";
    }

    @Override
    public String update(GradePointEntity gradePointEntity) {
        int i = gradePointEntityMapper.updateByPrimaryKey(gradePointEntity);
        if (i == 0){
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return "修改失败";
        }
        return "修改成功";
    }

    @Override
    public String delete(GradePointEntity gradePointEntity) {
        int temp = gradePointEntityMapper.deleteByPrimaryKey(gradePointEntity.getId());
        if(temp == 0){
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return "删除失败";
        }
        return "删除成功";
    }

    @Override
    public List<GradePointFilter> query(GradePointFilter gradePointFilter) {
        List<GradePointFilter> list = gradePointEntityMapper.query(gradePointFilter);
        return list;
    }

    @Override
    public Integer queryForCount(GradePointFilter gradePointFilter) {
        return gradePointEntityMapper.queryForCount(gradePointFilter);
    }

    @Override
    public List<String> selectForGradePoint() {
        return gradePointEntityMapper.selectForGradePoint();
    }
}
